package com.hp.bon.sgw.wh.utils;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;

import java.util.HashMap;
import java.util.Map;

public class XStreamFactory {

    private static volatile Map<String,XStream> streamMap = new HashMap<String, XStream>();


    private static volatile XStream xStream = null;


    public static XStream getStream(Class tClass) {
        XStream stream = null;
        if (streamMap.containsKey(tClass.getName())) {
            stream = streamMap.get(tClass.getName());
        } else {
            stream = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("-_", "_")));
            stream.alias("xml", tClass);
            streamMap.put(tClass.getName(), stream);
        }


        return stream;


    }


    public static XStream getXStream() {


        if (xStream == null) {
            xStream = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("-_", "_")));
        }


        return xStream;


    }


}
